package com.kzd.btgame.main.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.widget.ImageView
import com.kzd.btgame.R
import com.kzd.btgame.custom.setOnClickAntiShakeListener
import com.kzd.btgame.entity.HomeFab
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AlphaConfig
import razerdp.util.animation.AnimationHelper


class GiftImagePopup(context: Context, val onClick: (view: View, homeFab: HomeFab) -> Unit) :
    BasePopupWindow(context) {

    init {
        popupGravity = Gravity.CENTER
        setOverlayNavigationBar(false)
    }


    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_gift_image)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        contentView.findViewById<ImageView>(R.id.ivGiftImageClose).setOnClickAntiShakeListener {
            dismiss()
        }
        contentView.findViewById<ImageView>(R.id.ivGiftImageDoing).setOnClickAntiShakeListener {
            mHomeFab?.let { fab -> onClick(it, fab) }
            dismiss()
        }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.IN)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
//        val showAnimation: Animation = ScaleAnimation(1f, 0f, 1f, 0f)
//        showAnimation.duration = 500
//        return showAnimation
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.OUT)
            .toDismiss()
    }

    private var mHomeFab: HomeFab? = null

    fun setFillData(fab: HomeFab): GiftImagePopup {
        this.mHomeFab = fab
        contentView.findViewById<ImageView>(R.id.ivGiftImageDoing)
            .setImageResource(R.mipmap.ic_80006)
//            .loadCenterImage(fab.img ?: R.mipmap.big_xrfl_icon)
        return this
    }

}